package top.goldenyear.porpoise.framework.orm.core.interceptor;

import com.easy.query.core.basic.extension.interceptor.EntityInterceptor;
import com.easy.query.core.expression.sql.builder.EntityInsertExpressionBuilder;
import com.easy.query.core.expression.sql.builder.EntityUpdateExpressionBuilder;

/**
 * @author airhead
 */
public class ModelInterceptor implements EntityInterceptor {
  @Override
  public void configureInsert(
      Class<?> aClass, EntityInsertExpressionBuilder entityInsertExpressionBuilder, Object entity) {
    //    IModel model = (IModel) entity;
    //    if (model.getCreateTime() == null) {
    //      model.setCreateTime(LocalDateTime.now());
    //    }
    //
    //    if (model.getCreator() == null) {
    //      model.setCreator(ConvertUtil.toStr(UserContext.getLoginUserId()));
    //    }
    //
    //    if (model.getUpdateTime() == null) {
    //      model.setUpdateTime(LocalDateTime.now());
    //    }
    //
    //    if (model.getUpdater() == null) {
    //      model.setUpdater(ConvertUtil.toStr(UserContext.getLoginUserId()));
    //    }
  }

  @Override
  public void configureUpdate(
      Class<?> aClass, EntityUpdateExpressionBuilder entityUpdateExpressionBuilder, Object entity) {
    //    IModel model = (IModel) entity;
    //    model.setUpdateTime(LocalDateTime.now());
    //    model.setUpdater(ConvertUtil.toStr(UserContext.getLoginUserId()));
  }

  @Override
  public String name() {
    return ModelInterceptor.class.getSimpleName();
  }

  @Override
  public boolean apply(Class<?> entityClass) {
    //    return IModel.class.isAssignableFrom(entityClass);

    return true;
  }
}
